<template>
  <div>
    <ul>
      <li v-for="(i,index) in lyricsList" :key="index">
        {{ i.content }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "LyricsList",
  props: {
    lyrics: String
  },
  data() {
    return {
      lyricsList: null
    }
  },
  created() {
    // if (this.lyrics){
    //   console.log(this.lyrics)
    // }
    this.SongLyrics()
  },
  methods: {
    //  歌词处理
    SongLyrics() {
      this.lyricsList = this.lyrics.split('\n')
      // console.log(this.lyricsList)
      let lyricsListS = this.lyrics.split('\n')
      //  字符串   正则
      //  /\[\d*:\d*\.\d*\]/g
      let reg = /\[\d*:\d*\.\d*\]/g
      // console.log(this.lyrics.match(reg))
      if (!this.lyrics.match(reg)) {
        //  没有时间时
        //  不能使用  this.lyricsList
        this.lyricsList = lyricsListS.map(item => {
          return {
            time: -1,
            content: item
          }
        })
      }
      this.lyricsList=[]
      lyricsListS.forEach(item => {
        let min = Number(item.match(/\[\d*/)[0].replace(/\[/, ''))
        let miao = Number(item.match(/:\d*/)[0].replace(/:/, ''))
        let time = min * 60 + miao
        let content = item.replace(reg, '')  //没有的加空
        this.lyricsList.push({
          time,
          content,
        })
        console.log(this.lyricsList)
      })

      // console.log(this.lyricsList.item)


    }
  }
}
</script>

<style scoped lang="less">
ul {
  list-style: none;
  text-align: center;
  color: white;
  width: 100%;
  height: 320px;
  overflow: auto;
  padding: 10px 0;
  margin-top: 30px;
  color: #ccc;
}
</style>